<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>src\cmpage\controller\utils.js</title>
  
    <link rel="stylesheet" href="../assets/vendor/prettify/prettify-min.css">
    <link rel="stylesheet" href="../assets/css/main.css" id="site_styles">
    <link rel="stylesheet" href="../assets/vendor/bootstrap/css/bootstrap.min.css">
    <link rel="shortcut icon" type="image/png" href="../assets/favicon.png">
</head>
<body class="yui3-smart">
 <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container-fluid">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
               <a class="navbar-brand mainlogo" href="/static/doc/index.html">
             
            <img alt="" src="../assets/css/logo.png" title="">
            
                
          </a>
            </div>
            <div id="navbar" class="navbar-collapse collapse">
                 <ul class="nav navbar-nav">
                    
                    <li><a href="/home/index/index">首页</a>
                    </li>
                    
                    <li><a href="/static/doc/index.html">文档</a>
                    </li>
                    
                    <li><a href="/admin/index/index">演示</a>
                    </li>
                    
                    <li><a href="/home/index/log">日志</a>
                    </li>
                    
                </ul>
               <div class="navbar-form navbar-right filterAPi" autocomplete="off">
                <input type="text" id='txtSearchAPI' class="form-control search-query" placeholder="Search for API" />
                 <ul id="filterList" class="filterItems dropdown-menu" role="menu"></ul>
                </div>
            </div>
        </div>
    </nav>
    <div id="sidebar">
    <h3>Modules/Classes</h3>
        <div id="api-tabview-filter">
            <input id='txtSearch' type="search" class="form-control" placeholder="Type to filter Modules/Classes">
        </div>
        <dl id="sidebar_list">
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.controller.html">admin.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.controller.base.html">admin.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.code.html">admin.controller.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.index.html">admin.controller.index</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.controller.mob.html">admin.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/admin.model.html">admin.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/admin.model.code.html">admin.model.code</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_list.html">admin.model.code_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.code_lookup.html">admin.model.code_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser.html">admin.model.groupuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.groupuser_add.html">admin.model.groupuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.log.html">admin.model.log</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.login.html">admin.model.login</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.privilege.html">admin.model.privilege</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser.html">admin.model.teamuser</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.teamuser_add.html">admin.model.teamuser_add</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/admin.model.user.html">admin.model.user</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.controller.html">cmpage.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.controller.base.html">cmpage.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.mob.html">cmpage.controller.mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.module.html">cmpage.controller.module</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.page.html">cmpage.controller.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.controller.utils.html">cmpage.controller.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.logic.html">cmpage.logic</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.logic.page.html">cmpage.logic.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/cmpage.model.html">cmpage.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/cmpage.model.area.html">cmpage.model.area</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.base.html">cmpage.model.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.file_list.html">cmpage.model.file_list</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page.html">cmpage.model.page</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_excel.html">cmpage.model.page_excel</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_lookup.html">cmpage.model.page_lookup</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.page_mob.html">cmpage.model.page_mob</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.utils.html">cmpage.model.utils</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global.html">cmpage.cmpage_global</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.cmpage_global_flow.html">cmpage.cmpage_global_flow</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/demo.model.html">demo.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.proc_assign.html">flow.model.proc_assign</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/cmpage.model.appr.html">cmpage.model.appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.proc.html">flow.model.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task.html">flow.model.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act.html">flow.model.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.task_act_appr.html">flow.model.task_act_appr</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.controller.html">flow.controller</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.controller.act.html">flow.controller.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.base.html">flow.controller.base</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.proc.html">flow.controller.proc</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task.html">flow.controller.task</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.controller.task_act.html">flow.controller.task_act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
                <dt>
                    <span class="glyphicon glyphicon-minus"></span>
                    <a href="../modules/flow.model.html">flow.model</a>
                </dt>
                <dd>
                    <ul>
                   
                       <li>
                            
                           <a href="../classes/flow.model.act.html">flow.model.act</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                       <li>
                            
                           <a href="../classes/flow.model.act_path.html">flow.model.act_path</a>
                           <ul>
                                
                           </ul>
                       </li>
                    
                    </ul>
                </dd>
             
        </dl>
</div>
   
    <div class="stdoc-content">
        <!--     <form id="options-form" class="form-inline pull-right">
        Show:
        <label for="api-show-inherited" class="checkbox">
            <input type="checkbox" id="api-show-inherited" checked>
            Inherited
        </label>

        <label for="api-show-protected" class="checkbox">
            <input type="checkbox" id="api-show-protected">
            Protected
        </label>

        <label for="api-show-private" class="checkbox">
            <input type="checkbox" id="api-show-private">
            Private
        </label>
        <label for="api-show-deprecated" class="checkbox">
            <input type="checkbox" id="api-show-deprecated">
            Deprecated
        </label>

    </form>

 -->
        <div class="apidocs">
            <div id="docs-main">
                <div class="content">
                    <div class="page-header">
    <h1>src\cmpage\controller\utils.js <small>File</small></h1>
</div>

<div class="file">
    <pre class="prettyprint linenums" id='src_code'>
&#x27;use strict&#x27;;
// +----------------------------------------------------------------------
// | CmPage [ 通用页面框架 ]
// +----------------------------------------------------------------------
// | Licensed under the Apache License, Version 2.0
// +----------------------------------------------------------------------
// | Author: defans &lt;defans@sina.cn&gt;
// +----------------------------------------------------------------------

/**
 @module cmpage.controller
 */

/**
 * 工具集、其他URL接口
 * @class cmpage.controller.utils
 */
import Base from &#x27;./base.js&#x27;;

export default class extends Base {

    async testAction(){
//        let model = cmpage.model(&#x27;docu/base&#x27;);
//        let ret = await model.query(&#x27;select top 5 goods_name,goods_ucode from vw_docu_rec&#x27;);
        //let ret = await model.query(&quot;QueryPage &#x27;vw_docu_rec&#x27;,&#x27;c_id,goods_ucode,goods_name&#x27;,10,2,&#x27;&#x27;,&#x27;c_id&#x27;,0,&#x27;c_id&#x27;&quot;);

         let model = cmpage.model(&#x27;cmpage/base&#x27;);
         let ret = await model.query(&#x27;select c_name,c_time from t_customer limit 3&#x27;);
//        let ret = await this.model(&#x27;cmpage/page&#x27;).query(&#x27;select c_name,c_time from t_customer limit 2&#x27;);
        //debug(ret,&#x27;utils.C.test - ret&#x27;);
        console.log(ret);
        return this.json({});
    }

    /**
     * 根据URL参数直接调用相关model的相关方法， 调用： /cmpage/utils/callFunction?model=xxx&amp;fn=xxx&amp;parms=xxx,xxx
     * @method callFunction
     * @return {json}
     */
    async callFunctionAction(){
        let fnModel = cmpage.model(this.get(&#x27;model&#x27;));
        let fnName = this.get(&#x27;fn&#x27;);
        let ret = {statusCode:200, message:&#x27;&#x27;,data:{}};
        if(think.isFunction(fnModel[ fnName ])){
            //传入当前用户
            fnModel.user =  await this.session(&#x27;user&#x27;);
            if(think.isEmpty(this.get(&#x27;parms&#x27;))){
                ret.data = await fnModel[ fnName ]();
            }else{
                let parms = this.get(&#x27;parms&#x27;).split(&#x27;,&#x27;);
//                debug(parms, &#x27;utils.C.callFunction - parms&#x27;);
                ret.data = await fnModel[ fnName ]( ...parms );

            }
            if(!think.isEmpty(ret.data.statusCode))    ret.statusCode = ret.data.statusCode;
            if(!think.isEmpty(ret.data.message))    ret.message = ret.data.message;
        }else{
            ret = {statusCode:300, message:&#x27;您所调用的方法不存在!&#x27;,data:{}};
        }

        if(!think.isEmpty(this.get(&#x27;navtabid&#x27;)))   ret.navtabid = this.get(&#x27;navtabid&#x27;);
        if(!think.isEmpty(this.get(&#x27;dialogid&#x27;)))   ret.dialogid = this.get(&#x27;dialogid&#x27;);
        if(!think.isEmpty(this.get(&#x27;divid&#x27;)))   ret.divid = this.get(&#x27;divid&#x27;);

        return this.json(ret);
    }

    /**
     * 根据URL参数直接调用相关model的相关方法， 调用： /cmpage/utils/callFunction?model=xxx&amp;fn=xxx&amp;parms=xxx,xxx
     * @method callFunction
     * @return {json}
     */
    async callFunctionByModulenameAction(){
        let page = await this.model(&#x27;module&#x27;).getModuleByName(this.get(&#x27;modulename&#x27;));
        page.user = await this.session(&#x27;user&#x27;);
        //cmpage.debug(page);
        let pageModel = cmpage.model(think.isEmpty(page.c_path) ? &#x27;cmpage/page&#x27;:page.c_path);
        pageModel.mod = page;
        await pageModel.initPage();

        let fnName = this.get(&#x27;fn&#x27;);
        let ret = {statusCode:200, message:&#x27;&#x27;,data:{}};
        if(think.isFunction(pageModel[ fnName ])){
            if(think.isEmpty(this.get(&#x27;parms&#x27;))){
                ret.data = await pageModel[ fnName ]();
            }else{
                let parms = this.get(&#x27;parms&#x27;).split(&#x27;,&#x27;);
//                debug(parms, &#x27;utils.C.callFunction - parms&#x27;);
                ret.data = await pageModel[ fnName ]( ...parms );

            }
            if(!think.isEmpty(ret.data.statusCode))    ret.statusCode = ret.data.statusCode;
            if(!think.isEmpty(ret.data.message))    ret.message = ret.data.message;
        }else{
            ret = {statusCode:300, message:&#x60;您所调用的方法 ${page.c_modulename}/${fnName} 不存在!&#x60;,data:{}};
        }

        if(!think.isEmpty(this.get(&#x27;navtabid&#x27;)))   ret.navtabid = this.get(&#x27;navtabid&#x27;);
        if(!think.isEmpty(this.get(&#x27;dialogid&#x27;)))   ret.dialogid = this.get(&#x27;dialogid&#x27;);
        if(!think.isEmpty(this.get(&#x27;divid&#x27;)))   ret.divid = this.get(&#x27;divid&#x27;);

        return this.json(ret);
    }

    /**
     * 清除缓存， 调用： /cmpage/utils/clear_cache
     * @method  clearCache
     * @return {json}
     */
    async clearCacheAction(){
        //auto render template file index_index.html
        await this.model(&#x27;admin/code&#x27;).clearCodeCache();
        await this.model(&#x27;module&#x27;).clearModuleCache();
        await this.cache(&quot;users&quot;,null);

        return this.json({statusCode:200, message:&#x27;Cache is clear!&#x27;});
    }

    /**
     * 根据省份取城市列表， 调用： /cmpage/utils/get_citys?province=xxx
     * @method  getCitys
     * @return {json}
     */
    async getCitysAction(){
        let citys = await this.model(&#x27;area&#x27;).getCitys(this.get(&#x27;province&#x27;));
        let ret =[{value:&#x27;-1&#x27;, label:&#x27;请选择&#x27;}];
        for(let city of citys){
            ret.push({value:city.c_ucode, label:city.c_name});
        }
        return this.json(ret);
    }
    /**
     * 根据城市取区县列表， 调用： /cmpage/utils/get_countrys?city=xxx
     * @method  getCountrys
     * @return {json}
     */
    async getCountrysAction(){
        let countrys = await this.model(&#x27;area&#x27;).getCountrys(this.get(&#x27;city&#x27;));
        let ret =[{value:&#x27;-1&#x27;, label:&#x27;请选择&#x27;}];
        for(let country of countrys){
            ret.push({value:country.c_ucode, label:country.c_name});
        }
        return this.json(ret);
    }

}

    </pre>
</div>

                </div>
            </div>
        </div>
    </div>
<a id="gotoTop" class='well well-small' href='#'>
    Top
</a>
<script src="../assets/vendor/jquery/jquery-1.8.2.min.js"></script>
<script src="../assets/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="../assets/vendor/prettify/prettify-min.js"></script>
<script src="../assets/js/config.js"></script>
<script src="../assets/js/doc.js"></script>
</body>
</html>
